//
//  BNRHypnosisView.m
//  Quiz
//
//  Created by YaoJacob on 15/11/1.
//  Copyright © 2015年 Roger. All rights reserved.
//

#import "BNRHypnosisView.h"

@interface BNRHypnosisView()
@property (strong, nonatomic) UIColor *circleColor;
@end

@implementation BNRHypnosisView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.circleColor = [UIColor lightGrayColor];
    }
    
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    CGRect bounds = self.bounds;
    
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width/2;
    center.y = bounds.origin.y + bounds.size.height/2;
    
    //    float radius = (MIN(bounds.size.width, bounds.size.height)/2.0);
    
    float maxRadius = hypot(bounds.size.width, bounds.size.height)/2.0;
    
    UIBezierPath *path = [[UIBezierPath  alloc]init];
    
    //    [path addArcWithCenter:center radius:radius startAngle:0.0 endAngle:M_PI  *2.0 clockwise:YES];
    
    for (float curRadius = maxRadius; curRadius > 0; curRadius -= 20) {
        [path moveToPoint:CGPointMake(center.x + curRadius, center.y)];
        [path addArcWithCenter:center radius:curRadius startAngle:0.0 endAngle:M_PI  *2.0 clockwise:YES];
    }
    
    path.lineWidth = 10;
    //    [[UIColor lightGrayColor] setStroke];
    [self.circleColor setStroke]; //动态颜色
    [path stroke];
    
    //
    UIImage *logo = [UIImage imageNamed:@"logo.png"]; //path is ok.
    [logo drawInRect:bounds];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%@ was touch", self);
    
    float r = (arc4random() % 100) /100.0;
    float g = (arc4random() % 100) /100.0;
    float b = (arc4random() % 100) /100.0;

    self.circleColor = [UIColor colorWithRed:r green:g blue:b alpha:1.0];
    [self setNeedsDisplay];

}

@end
